package com.bt.lms.ui.page.info;

import com.bt.lms.ui.action.teacher.basic.info.AddTeacher;
import com.bt.lms.ui.action.teacher.basic.info.CheckEditTeacherInfo;
import com.bt.lms.ui.action.teacher.basic.info.CheckTeacherBasicInfo;
import com.bt.lms.ui.vo.teacherBasicInfo.TeacherBasicInfoList;
import com.bt.lms.ui.page.sys.style.BtnStyle;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;

import java.util.ArrayList;
import java.util.List;

/**
 * 教师基本信息列表界面
 */
public class PageTeacherBasicInfo extends VBox {

    private Integer width=1280;

    private Integer height =900;
    public PageTeacherBasicInfo(){

    this.setPrefWidth(width);
    this.setPrefHeight(height);

        //当前位置
        HBox locationHBox = new HBox();
        locationHBox.setPadding(new Insets(15,15,15,15));
        locationHBox.setPrefWidth(width);
        double locationHBoxHeight=height*0.1;
        locationHBox.setPrefHeight(locationHBoxHeight);
        Label label1 = new Label("当前位置：🏠>教学管理>教师管理");
        Font font = Font.font("仿宋", FontWeight.THIN, FontPosture.REGULAR,18);
        label1.setFont(font);
        locationHBox.getChildren().add(label1);
        this.getChildren().add(locationHBox);

        //分页查询
        HBox topHBox = new HBox();
        topHBox.setPadding(new Insets(15,15,15,15));
        double topHBoxHeight=height*0.1;
        topHBox.setPrefHeight(topHBoxHeight);
        topHBox.setPrefWidth(width);
        topHBox.setSpacing(20);
        Label teacherNameLb = new Label("教师姓名:");
        TextField teacherNameTf = new TextField();
        Label affiliatedUnitLb = new Label("所属的学习中心:");
        TextField affiliatedUnitTf = new TextField();
        Button searchBtn = new Button("搜索");
        searchBtn.setPrefWidth(70);
        searchBtn.setStyle("-fx-background-color: #00a6ff");
        topHBox.getChildren().addAll(teacherNameLb,teacherNameTf,affiliatedUnitLb,affiliatedUnitTf,searchBtn);
        this.getChildren().add(topHBox);

        //新增教师按钮
        HBox addHBox = new HBox();
        addHBox.setPadding(new Insets(15,15,15,15));
        addHBox.setPrefWidth(width);
        double btnHBoxHeight=height*0.05;
        addHBox.setPrefHeight(btnHBoxHeight);
        Button addBtn = new Button("新增教师");
        BtnStyle.addBtn(addBtn);
        addBtn.setPrefWidth(150);
        addBtn.setPrefHeight(40);
        addHBox.getChildren().add(addBtn);
        this.getChildren().add(addHBox);
        //加事件
        AddTeacher addTeacherAction = new AddTeacher();
        addBtn.setOnAction(addTeacherAction);

        //创建一个表格组件
        TableView table = new TableView();
        table.setPrefWidth(width);
        table.setPrefHeight(height*0.65);
        //创建列
        TableColumn teacherNameCol = new TableColumn<>("教师姓名");
        TableColumn accountCol = new TableColumn<>("教师姓账号");
        TableColumn theirUnitCol = new TableColumn<>("所属的学习中心");
        TableColumn positionCol = new TableColumn<>("职位");
        TableColumn movePhoneCol = new TableColumn<>("移动电话");
        TableColumn phoneCol = new TableColumn<>("其他电话");
        TableColumn onJobStateCol = new TableColumn<>("在职状态");
        TableColumn enableStateCol = new TableColumn<>("启用状态");
        TableColumn operateCol = new TableColumn<>("操作");

        //把列放入表格
        ObservableList columns = table.getColumns();
        columns.addAll(teacherNameCol,accountCol,theirUnitCol,positionCol,movePhoneCol,phoneCol,onJobStateCol,enableStateCol,operateCol);

        //加入数据放入表格中
        //教师名称盒子(数据1)
        Color color = Color.rgb(99, 212, 238, 1);
        HBox nameHBox1 = new HBox();
        Label nameLb1 = new Label("李毅");
        nameLb1.setTextFill(color);
        nameHBox1.getChildren().add(nameLb1);
        //查看教师基本详情界面
        CheckTeacherBasicInfo checkTeacherBasicInfo = new CheckTeacherBasicInfo();
        nameLb1.setOnMouseClicked(checkTeacherBasicInfo);
        //教师名称盒子(数据2)
        HBox nameHBox2 = new HBox();
        Label nameLb2 = new Label("李毅");
        nameLb2.setTextFill(color);
        nameHBox2.getChildren().add(nameLb2);
        //教师名称盒子(数据3)
        HBox nameHBox3 = new HBox();
        Label nameLb3 = new Label("李毅");
        nameLb3.setTextFill(color);
        nameHBox3.getChildren().add(nameLb3);
        //教师名称盒子(数据4)
        HBox nameHBox4 = new HBox();
        Label nameLb4 = new Label("李毅");
        nameLb4.setTextFill(color);
        nameHBox4.getChildren().add(nameLb4);

        //操作盒子（数据1）
        HBox operateHBox1 = new HBox();
        operateHBox1.setSpacing(10);
        Label editLb = new Label("编辑");
        Label stopLb = new Label("暂停");
        editLb.setTextFill(color);
        stopLb.setTextFill(color);
        operateHBox1.getChildren().addAll(editLb,stopLb);
        //查看/编辑事件
        CheckEditTeacherInfo checkEditTeacherInfo = new CheckEditTeacherInfo();
        editLb.setOnMouseClicked(checkEditTeacherInfo);
        //操作盒子（数据1）
        HBox operateHBox2 = new HBox();
        operateHBox2.setSpacing(10);
        Label editLb1 = new Label("编辑");
        Label stopLb1 = new Label("暂停");
        editLb1.setTextFill(color);
        stopLb1.setTextFill(color);
        operateHBox2.getChildren().addAll(editLb1,stopLb1);
        //操作盒子（数据1）
        HBox operateHBox3 = new HBox();
        operateHBox3.setSpacing(10);
        Label editLb2 = new Label("编辑");
        Label stopLb2 = new Label("暂停");
        editLb2.setTextFill(color);
        stopLb2.setTextFill(color);
        operateHBox3.getChildren().addAll(editLb2,stopLb2);
        //操作盒子（数据1）
        HBox operateHBox4 = new HBox();
        operateHBox4.setSpacing(10);
        Label editLb3 = new Label("编辑");
        Label stopLb3 = new Label("暂停");
        editLb3.setTextFill(color);
        stopLb3.setTextFill(color);
        operateHBox4.getChildren().addAll(editLb3,stopLb3);


        TeacherBasicInfoList teacherBasicInfoList01 = new TeacherBasicInfoList(nameHBox1,"liyi@163.com","西南大学","教授","13581801098","010-89320912","在职","启用",operateHBox1);
        TeacherBasicInfoList teacherBasicInfoList02 = new TeacherBasicInfoList(nameHBox2,"liyi@163.com","西南大学","教授","13581801098","010-89320912","在职","启用",operateHBox2);
        TeacherBasicInfoList teacherBasicInfoList03 = new TeacherBasicInfoList(nameHBox3,null,"西南大学",null,"13581801098","010-89320912","在职","停用",operateHBox3);
        TeacherBasicInfoList teacherBasicInfoList04 = new TeacherBasicInfoList(nameHBox4,null,"西南大学",null,"13581801098","010-89320912","离职",null,operateHBox4);


        //放入集合
        List<TeacherBasicInfoList> teacherBasicInfoList=new ArrayList<>();
        teacherBasicInfoList.add(teacherBasicInfoList01);
        teacherBasicInfoList.add(teacherBasicInfoList02);
        teacherBasicInfoList.add(teacherBasicInfoList03);
        teacherBasicInfoList.add(teacherBasicInfoList04);

        //将用户数据集合转成Javafx组件集合
        ObservableList<TeacherBasicInfoList> teacherBasicInfoLists = FXCollections.observableArrayList(teacherBasicInfoList);
        //把数据放入表格中
        table.setItems(teacherBasicInfoLists);

        //映射
        teacherNameCol.setCellValueFactory(new PropertyValueFactory<TeacherBasicInfoList,HBox>("teacherName"));
        accountCol.setCellValueFactory(new PropertyValueFactory<TeacherBasicInfoList,String>("account"));
        theirUnitCol.setCellValueFactory(new PropertyValueFactory<TeacherBasicInfoList,String>("theirUnit"));
        positionCol.setCellValueFactory(new PropertyValueFactory<TeacherBasicInfoList,String>("position"));
        movePhoneCol.setCellValueFactory(new PropertyValueFactory<TeacherBasicInfoList,String>("movePhone"));
        phoneCol.setCellValueFactory(new PropertyValueFactory<TeacherBasicInfoList,String>("phone"));
        onJobStateCol.setCellValueFactory(new PropertyValueFactory<TeacherBasicInfoList,String>("onJobState"));
        enableStateCol.setCellValueFactory(new PropertyValueFactory<TeacherBasicInfoList,HBox>("enableState"));
        operateCol.setCellValueFactory(new PropertyValueFactory<TeacherBasicInfoList,HBox>("operate"));

        this.getChildren().add(table);

        //分页
        HBox layPageHBox = new HBox();
        layPageHBox.setPadding(new Insets(15,15,15,15));
        layPageHBox.setAlignment(Pos.CENTER_RIGHT);//内部组件的位置
        layPageHBox.setSpacing(20);
        double layPageHBoxHeight=900*0.1;
        layPageHBox.setPrefHeight(layPageHBoxHeight);
        layPageHBox.setPrefWidth(1280);
        Label homePageLb = new Label("<<首页   <<上一页");
        Color color1 = Color.rgb(20, 100, 7, 1);
        homePageLb.setTextFill(color1);
        Button firstPageBtn = new Button("1");
        firstPageBtn.setStyle("-fx-background-color: #2f982f");

        Button secondPageBtn = new Button("2");
        Button thirdPageBtn = new Button("3");
        Button fourthlyPageBtn = new Button("4");
        Label nextPage = new Label("下一页>>    尾页>>");
        nextPage.setTextFill(color1);
        Label totalLb = new Label("总记录数100条");
        TextField pageTF = new TextField();
        pageTF.setMaxWidth(40);
        Label label2 = new Label("/10");
        Button goBtn = new Button("GO");
        goBtn.setStyle("-fx-background-color: #63d4ee");


        layPageHBox.getChildren().addAll(homePageLb,firstPageBtn,secondPageBtn,thirdPageBtn,fourthlyPageBtn,nextPage,totalLb,pageTF,label2,goBtn);
        this.getChildren().add(layPageHBox);




    }


}
